<?php

	
		//BEGIN GET UNDERWRITERS
		$UWQuery = "SELECT * FROM $underwriter_Table ORDER BY name asc";
		$resultUW = $db->getAll($UWQuery, DB_FETCHMODE_ASSOC);
		if (DB::isError($resultUW)) {
		die ($resultUW->getMessage());
		}
		
		//BEGIN GET AIRTIMES
		$ATQuery = "SELECT * from $airtimes_Table ORDER BY military";
		$resultAT = $db->getAll($ATQuery, DB_FETCHMODE_ASSOC);
		if (DB::isError($resultAT)) {
		die ($resultAT->getMessage());
		}
				
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						//BEGIN JAVASCRIPT FUNCTION TO NULL UNUSED DAYS ACCORDING TO AIRTIMES
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						echo"<script language=\"JavaScript\" type=\"text/javascript\">
						<!--
						//Array to hold days and values
						
						function timeEntry(time,mon,tue,wed,thu,fri,sat,sun){
						this.time = time;
						this.mon = mon;
						this.tue = tue;
						this.wed = wed;
						this.thu = thu;
						this.fri = fri;
						this.sat = sat;
						this.sun = sun;
						}
						
						var javaAT = new Array(" . count($resultAT) . ");
						";
						
						
						$a = 0;
						while($a < count($resultAT)){
						echo "javaAT[$a] = new timeEntry(\"".$resultAT[$a][hour].":".$resultAT[$a][minute].":".$resultAT[$a][ampm]."\",\"".$resultAT[$a][mon]."\",\"".$resultAT[$a][tue]."\",\"".$resultAT[$a][wed]."\",\"".$resultAT[$a][thu]."\",\"".$resultAT[$a][fri]."\",\"".$resultAT[$a][sat]."\",\"".$resultAT[$a][sun]."\");\n";
						++$a;
						}
					
						echo "function nullDays(pointer){
						var dropDown = eval(\"document.form.time\" + pointer + \".value\");
						
						for (var q=0; q <".count($resultAT)."; q++) {
							if(dropDown == javaAT[q].time){
							
								if(javaAT[q].mon != 'true'){
								var mon = \"document.form.mon\" + pointer + \".checked = false\";
								eval(mon);
								var mon = \"document.form.mon\" + pointer + \".disabled = true\";
								eval(mon);
								}else{
								var mon = \"document.form.mon\" + pointer + \".disabled = false\";
								eval(mon);	
								}
								
								if(javaAT[q].tue != 'true'){
								var tue = \"document.form.tue\" + pointer + \".checked = false\";
								eval(tue);								
								var tue = \"document.form.tue\" + pointer + \".disabled = true\";
								eval(tue);
								}else{
								var tue = \"document.form.tue\" + pointer + \".disabled = false\";
								eval(tue);	
								}								
								
								if(javaAT[q].wed != 'true'){
								var wed = \"document.form.wed\" + pointer + \".checked = false\";
								eval(wed);								
								var wed = \"document.form.wed\" + pointer + \".disabled = true\";
								eval(wed);
								}else{
								var wed = \"document.form.wed\" + pointer + \".disabled = false\";
								eval(wed);	
								}								
									
								if(javaAT[q].thu != 'true'){
								var thu = \"document.form.thu\" + pointer + \".checked = false\";
								eval(thu);								
								var thu = \"document.form.thu\" + pointer + \".disabled = true\";
								eval(thu);
								}else{
								var thu = \"document.form.thu\" + pointer + \".disabled = false\";
								eval(thu);	
								}								
								
								if(javaAT[q].fri != 'true'){
								var fri = \"document.form.fri\" + pointer + \".checked = false\";
								eval(fri);								
								var fri = \"document.form.fri\" + pointer + \".disabled = true\";
								eval(fri);
								}else{
								var fri = \"document.form.fri\" + pointer + \".disabled = false\";
								eval(fri);	
								}								
									
								if(javaAT[q].sat != 'true'){
								var sat = \"document.form.sat\" + pointer + \".checked = false\";
								eval(sat);								
								var sat = \"document.form.sat\" + pointer + \".disabled = true\";
								eval(sat);
								}else{
								var sat = \"document.form.sat\" + pointer + \".disabled = false\";
								eval(sat);	
								}							
									
								if(javaAT[q].sun != 'true'){
								var sun = \"document.form.sun\" + pointer + \".checked = false\";
								eval(sun);								
								var sun = \"document.form.sun\" + pointer + \".disabled = true\";
								eval(sun);
								}else{
								var sun = \"document.form.sun\" + pointer + \".disabled = false\";
								eval(sun);	
								}								

							break;
							}
						}
						
						//alert(javaAT[10].time);
						//alert(mon);
						}
						//-->
						</script>";
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						//END JAVASCRIPT FUNCTION TO NULL UNUSED DAYS ACCORDING TO AIRTIMES
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++			
						
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
						//BEGIN JAVASCRIPT FUNCTION TO ENABLE ALL CHECKBOXES
						//++++++++++++++++++++++++++++++++++++++++++++++++++
						echo "<script language=\"JavaScript\" type=\"text/javascript\">
						<!--
						function resetForm(){
							for (var q=0; q < document.form.elements.length; q++) {
							 // get each element of form form
							 var e = document.form.elements[q];
			
							 if( e.type == \"checkbox\"){
							 e.disabled = false;
							}
							

			
						}//end loop

						document.form.reset();
						
						for (var q=0; q < document.form.elements.length; q++) {
							 // get each element of form form
							 var e = document.form.elements[q];
			
							 if(e.name.indexOf('time') != -1){
							 var text = e.name;
							 var pointer = text.substring(4,text.length);
							 //alert(pointer);
							 nullDays(pointer);
							}
							

			
						}//end loop
						
						}//end function
						//-->
						</script> ";
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
						//END JAVASCRIPT FUNCTION TO ENABLE ALL CHECKBOXES
						//++++++++++++++++++++++++++++++++++++++++++++++++++			
						
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
						//BEGIN JAVASCRIPT FORM CHECK
						//++++++++++++++++++++++++++++++++++++++++++++++++++						
						echo("<script type=\"text/javascript\" language=\"JavaScript\">
						function formCheck(){
						var cMsg = \"\";");
						
						$q = 1;
						$i = 0;
						while($i < count($_SESSION['updateArray'])){
									
						echo "if(document.form.name$i.value==\"\"){
						cMsg += \"\\t\" + \"Update Item $q: Underwriter Name\" + \"\\n\";
						}
						if(document.form.length$i.value==\"\"){
						cMsg += \"\\t\" + \"Update Item $q: Spot Length\" + \"\\n\";
						}";
						
						
						echo "
						if(document.form.rate$i.value==\"\" && document.form.trade$i.checked != true){
						cMsg += \"\\t\" + \"Update Item $q: Rate\" + \"\\n\";
						}else if(document.form.rate$i.value==\"\" && document.form.trade$i.checked == true){
						document.form.rate$i.value=\"NA\"
						}else if(document.form.rate$i.value!=\"NA\" && document.form.rate$i.value!=\"0.00\"){
						document.form.trade$i.checked=false;
						}else{
						document.form.trade$i.checked=true;
						document.form.rate$i.value=\"NA\"
						}";
						
						echo "
						if(document.form.time$i.value==\"not_selected\"){
						cMsg += \"\\t\" + \"Update Item $q: Time\" + \"\\n\";
						}";
								
						echo "if(document.form.mon$i.checked == false && document.form.tue$i.checked == false && document.form.wed$i.checked == false && document.form.thu$i.checked == false && document.form.fri$i.checked == false && document.form.sat$i.checked == false && document.form.sun$i.checked == false){
						cMsg += \"\\t\" + \"Update Item $q: Day(s) of Week\" + \"\\n\";
						}";
						++$i;
						++$q;
						}
						echo("if( cMsg != \"\" ){
			
						// we have some deletes to confirm
					
						cMsg = \"Please complete the following fields:\\n\\n\" + cMsg + \"\\n\";
					
						alert(cMsg)
						}else {
						document.form.submit();
						}										
			
						
						} 
						// -->
						</script>");			
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
						//END JAVASCRIPT FORM CHECK
						//++++++++++++++++++++++++++++++++++++++++++++++++++				
		
		echo("<TR><TD valign=\"top\" align=\"center\">");
		
		$i = 0;
		while($i < count($_SESSION['updateArray'])){
		$myID = $_SESSION['updateArray']["$i"];
		
		$UDQuery = "SELECT * FROM $grid_Table WHERE ID = '$myID'";
		$resultUD = $db->getAll($UDQuery, DB_FETCHMODE_ASSOC);
		if (DB::isError($resultUD)) {
		die ($resultUD->getMessage());
		}
		
    	$underwriter = stripslashes($resultUD[0]["underwriter"]);
    	$abbreviation = stripslashes($resultUD[0]["abbreviation"]);
    	$startTimeStamp = $resultUD[0]["startTimeStamp"];
    	$endTimeStamp = $resultUD[0]["endTimeStamp"];
    	$length = $resultUD[0]["length"];
    	$spotID = $resultUD[0]["spotID"];
    	$hour = $resultUD[0]["hour"];
    	$minute = $resultUD[0]["minute"];
    	$seconds = $resultUD[0]["seconds"];
    	$ampm = $resultUD[0]["ampm"];
    	$military = $resultUD[0]["military"];
    	$mon = $resultUD[0]["mon"];
    	$tue = $resultUD[0]["tue"];
    	$wed = $resultUD[0]["wed"];
    	$thu = $resultUD[0]["thu"];
    	$fri = $resultUD[0]["fri"];
    	$sat = $resultUD[0]["sat"];
    	$sun = $resultUD[0]["sun"];
    	$type = $resultUD[0]["type"];
    	$rate = $resultUD[0]["rate"];
    	$live = $resultUD[0]["live"];
    	$trade = $resultUD[0]["trade"];
		//REPEATING SECTION
		echo ("<INPUT name=\"maintainViewStamp\" type=\"hidden\" value=\"" . $_SESSION['timestamp'] . "\">");
			echo("<script language=\"JavaScript\" type=\"text/javascript\">
			<!--
			function addAbreviation$i(){
			document.form.spotID$i.value = document.form.name$i.value;
			}
			//-->
			</script> \n\n ");	
			
			echo "<INPUT name=\"upDateID$i\" type=\"hidden\" value=\"" . $_SESSION['updateArray']["$i"] . "\"> \n ";
			
			echo("<TABLE border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"> \n
			<tr class=\"blockHeader\"><td valign=\"top\" align=\"right\">UPDATE ITEM ". ($i + 1) . ":</td>  <td valign=\"top\" align=\"left\"> $underwriter</td></tr>
					<TR class=\"even\"><TD class=\"formDescriptiveText\">Underwriter:</TD> <TD valign=\"top\" align=\"left\"> \n");
						//#####################################
						// UPDATE  Item - Underwriter Drop Down List
						//#####################################
						
						echo("<select name=\"name$i\" size=\"1\" onChange = \"addAbreviation$i()\"><option value=\"\">Choose an underwriter:</option>\n");
						
						//$Query = mysql_query("SELECT * FROM underwriters ORDER BY name asc", $link);
						$l = 0;
						while ($l < count($resultUW)) {
						$ID = $resultUW[$l]["ID"];
						$name = $resultUW[$l]["name"];
						$abbreviation = $resultUW[$l]["abbreviation"];
							if($name == $underwriter){
								echo("<option value=\"$abbreviation\" selected>$name</option>\n"); 
							}else{
								echo("<option value=\"$abbreviation\">$name</option>\n"); 
							}
							++$l;
						}//End Loop
						echo("</select>\n\n");
						//#####################################
						// UPDATE Item - Start Date
						//#####################################
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Start Date:</TD>  <TD valign=\"top\" align=\"left\">\n");
				        $todaysMonth = date("n");
						$todaysDay = date("j");
						$todaysYear = date("Y");
						$monthsText = array("January","February","March","April","May","June","July","August","September","October","November","December");
						
						//Month Drop Down List
						echo("<select name=\"startMonth$i\" size=\"1\">\n");
						$MYi = 0;
						$MYq = 1;
						while($MYi < 12){
						if($MYq == date("n", $startTimeStamp)){
								echo("<option value=\"$MYq\" selected>$monthsText[$MYi]</option>\n");
								}else{
								echo("<option value=\"$MYq\">$monthsText[$MYi]</option>\n");
								}						
						++$MYi;
						++$MYq;
						}
						echo("</SELECT>\n\n");			
						
						
						//Day Drop Down List
						echo("<select name=\"startDay$i\" size=\"1\" >\n");
						$MYi = 0;
						$MYq = 1;
						while($MYi < 31){
								if($MYq == date("j", $startTimeStamp)){
								echo("<option value=\"$MYq\" selected>$MYq</option>\n");
								}else{
								echo("<option value=\"$MYq\">$MYq</option>\n");
								}
							
						++$MYi;
						++$MYq;
						}
						echo("</SELECT>\n\n");
						
						
						//Year Drop Down List
						echo("<select name=\"startYear$i\" size=\"1\"> \n");
						
						for ($h = $yearToStartRecords; $h < date("Y"); $h++) {
						
									if($h == date("Y", $startTimeStamp)){
									echo("<option value=\"" . $h . "\" selected>" . $h . "</option>\n");
									}else{
									echo("<option value=\"" . $h . "\">" . $h . "</option>\n");
									}
						} 
							$MYi = 0;
							while($MYi < 5){
									$futureYears = ($todaysYear + $MYi);
									if($futureYears == date("Y", $startTimeStamp)){
									echo("<option value=\"$futureYears\" selected>$futureYears</option> \n");
									}else{
									echo("<option value=\"$futureYears\">$futureYears</option> \n");
									}
							++$MYi;
							}
						
						echo("</SELECT> \n");
					    echo("</TD></TR> \n \n");									
						
						
						//#####################################
						//UPDATE ITEM - End Date						
						//#####################################
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">End Date:</TD>  <TD valign=\"top\" align=\"left\"> \n");

						//Month Drop Down List
						echo("<select name=\"endMonth$i\" size=\"1\">\n");
							if($endTimeStamp == 'NA'){
								echo("<option value=\"NA\" selected>NA</option> \n");
								$MYi = 0;
								$MYq = 1;
								while($MYi < 12){
									echo("<option value=\"$MYq\">$monthsText[$MYi]</option>\n");
								++$MYi;
								++$MYq;
								}															
							}else{
								echo("<option value=\"NA\">NA</option> \n");
								$MYi = 0;
								$MYq = 1;
								while($MYi < 12){
									if($MYq == date("n", $endTimeStamp)){
									echo("<option value=\"$MYq\" selected>$monthsText[$MYi]</option>\n");
									}else{
									echo("<option value=\"$MYq\">$monthsText[$MYi]</option>\n");
									}
								++$MYi;
								++$MYq;
								}							
							}
							
						echo("</SELECT>\n\n");

						
						//Day Drop Down List
						echo("<select name=\"endDay$i\" size=\"1\"> \n");
							if($endTimeStamp == 'NA'){
							echo("<option value=\"NA\" selected>NA</option> \n");
							$MYi = 0;
							$MYq = 1;
							while($MYi < 31){
								echo("<option value=\"$MYq\">$MYq</option>\n");
							++$MYi;
							++$MYq;
							}						
								
							}else{
							echo("<option value=\"NA\">NA</option> \n");
							$MYi = 0;
							$MYq = 1;
							while($MYi < 31){
								if($MYq == date("j", $endTimeStamp)){
								echo("<option value=\"$MYq\" selected>$MYq</option>\n");
								}else{
								echo("<option value=\"$MYq\">$MYq</option>\n");
								}
							
							++$MYi;
							++$MYq;
							}													
							}						
						
						echo("</SELECT> \n \n");
						
						
						//Year Drop Down List
						echo("<select name=\"endYear$i\" size=\"1\"> \n");

							if($endTimeStamp == 'NA'){
							echo("<option value=\"NA\" selected>NA</option> \n");
							
						for ($h = $yearToStartRecords; $h < date("Y"); $h++) {
							echo("<option value=\"" . $h . "\">" . $h . "</option>\n");
						} 
								$MYi = 0;
								while($MYi < 5){
									$futureYears = ($todaysYear + $MYi);
									echo("<option value=\"$futureYears\">$futureYears</option> \n");
									++$MYi;
								}
							
							}else{
							echo("<option value=\"NA\">NA</option> \n");
							
						for ($h = $yearToStartRecords; $h < date("Y"); $h++) {
						
									if($h == date("Y", $endTimeStamp)){
									echo("<option value=\"" . $h . "\" selected>" . $h . "</option>\n");
									}else{
									echo("<option value=\"" . $h . "\">" . $h . "</option>\n");
									}
						} 
						
							$MYi = 0;
							while($MYi < 5){
									$futureYears = ($todaysYear + $MYi);
									if($futureYears == date("Y", $endTimeStamp)){
									echo("<option value=\"$futureYears\" selected>$futureYears</option> \n");
									}else{
									echo("<option value=\"$futureYears\">$futureYears</option> \n");
									}
							++$MYi;
							}
							
							}
						
						echo("</SELECT> \n");
					    echo("</TD></TR> \n");	
						//#####################################
						//UPDATE ITEM - Length						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Spot Length:</TD>  <TD class=\"formElementTextLeft\" align=\"left\"> \n");
						echo("<INPUT name=\"length$i\" type=\"text\" value = \"$length\"> <FONT size=\"-1\">(Seconds)</FONT> \n");
					    echo("</TD></TR> \n");	
						//#####################################
						//UPDATE ITEM - ID/AV# 						
						//#####################################				
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Spot ID:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						echo("<INPUT name=\"spotID$i\" type=\"text\" value=\"$spotID\"> <FONT size=\"-1\"></FONT> \n");
					    echo("</TD></TR> \n \n");
						//#####################################
						//UPDATE - Air Time 						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Air time:</TD>  <TD valign=\"top\" align=\"left\">\n");
							echo("<select name=\"time$i\" size=\"1\" onChange=\"nullDays($i)\"> \n");
							$n=0;
							while ($n < count($resultAT)) {
							$DBhour = $resultAT[$n]["hour"];
							$DBminute = $resultAT[$n]["minute"];
							$DBampm = $resultAT[$n]["ampm"];
								if($DBhour == $hour && $DBminute == $minute && $DBampm == $ampm){
									$ATPointer = $n;
								echo("<option value=\"$DBhour:$DBminute:$DBampm\" selected>$DBhour:$DBminute $DBampm</option> \n");   
								}else{
								echo("<option value=\"$DBhour:$DBminute:$DBampm\">$DBhour:$DBminute $DBampm</option> \n");   
								}
								++$n;
							}//end loop
							echo("</SELECT> \n \n");				

							echo(" : <select name=\"seconds$i\" size=\"1\">");
							if($seconds == '00'){
							echo("<option value=\"00\" selected>00 Seconds</option><option value=\"30\">30 Seconds</option></SELECT> &nbsp; \n \n");
							}else{
							echo("<option value=\"00\">00 Seconds</option><option value=\"30\" selected>30 Seconds</option></SELECT> &nbsp; \n \n");
							}				
										    
						echo("</TD></TR> \n \n");		
						//#####################################
						//UPDATE - Days of Week 						
						//#####################################	
						//form through Airtime array and find matching time entry
						
						//++++++++++++++++++++++++++++++++++++++++++++++++++++++++						
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Day(s) of week:</TD>  <TD > \n");
						echo("<TABLE width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><TR> \n");
							if($mon == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"mon$i\" type=\"checkbox\" value=\"true\" checked>Mon &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][mon] != 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"mon$i\" type=\"checkbox\" value=\"true\" disabled>Mon &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"mon$i\" type=\"checkbox\" value=\"true\">Mon &nbsp;&nbsp;</TD> \n");
							}
							if($tue == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"tue$i\" type=\"checkbox\" value=\"true\" checked>Tue &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][tue] != 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"tue$i\" type=\"checkbox\" value=\"true\" disabled>Tue &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"tue$i\" type=\"checkbox\" value=\"true\">Tue &nbsp;&nbsp;</TD> \n");
							}
							if($wed == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"wed$i\" type=\"checkbox\" value=\"true\" checked>Wed &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][wed] != 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"wed$i\" type=\"checkbox\" value=\"true\" disabled>Wed &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"wed$i\" type=\"checkbox\" value=\"true\">Wed &nbsp;&nbsp;</TD> \n");
							}
							if($thu == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"thu$i\" type=\"checkbox\" value=\"true\" checked>Thu &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][thu] != 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"thu$i\" type=\"checkbox\" value=\"true\" disabled>Thu &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"thu$i\" type=\"checkbox\" value=\"true\">Thu &nbsp;&nbsp;</TD> \n");
							}
							if($fri == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"fri$i\" type=\"checkbox\" value=\"true\" checked>Fri &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][fri] != 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"fri$i\" type=\"checkbox\" value=\"true\" disabled>Fri &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"fri$i\" type=\"checkbox\" value=\"true\">Fri &nbsp;&nbsp;</TD> \n");
							}
							if($sat == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sat$i\" type=\"checkbox\" value=\"true\" checked>Sat &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][sat] != 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sat$i\" type=\"checkbox\" value=\"true\" disabled>Sat &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sat$i\" type=\"checkbox\" value=\"true\">Sat &nbsp;&nbsp;</TD> \n");
							}
							if($sun == 'true'){
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sun$i\" type=\"checkbox\" value=\"true\" checked>Sun &nbsp;&nbsp;</TD> \n");
							}else if($resultAT[$ATPointer][sun] != 'true'){ 
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sun$i\" type=\"checkbox\" value=\"true\" disabled>Sun &nbsp;&nbsp;</TD> \n");
							}else{
							echo("<TD class=\"formElementTextLeft\"><INPUT name=\"sun$i\" type=\"checkbox\" value=\"true\">Sun &nbsp;&nbsp;</TD> \n");
							}
						echo("</TR></TABLE> \n");
						echo("</TD></TR> \n \n");													
						//#####################################
						//UPDATE - TYPE: EPSA or UW 						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Type:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						echo("<select name=\"type$i\" size=\"1\" > \n");

							if($type == 'UW'){
							echo("<option value=\"UW\" selected>Underwriter</option> \n");
 							echo("<option value=\"PSA\">PSA</option> \n");
							}else{
							echo("<option value=\"UW\">Underwriter</option> \n");
 							echo("<option value=\"PSA\" selected>PSA</option> \n");
							}
						echo("</SELECT></TD></TR> \n \n");		
						//#####################################
						//UPDATE - Rate 						
						//#####################################				
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Rate:</TD>  <TD valign=\"top\" align=\"left\"> \n");
						echo("<INPUT name=\"rate$i\" type=\"text\" value=\"" . $rate . "\"> \n");
					    echo("</TD></TR> \n \n");						
						//#####################################
						//UPDATE - Live Read 						
						//#####################################				
					    echo("<TR class=\"odd\"><TD class=\"formDescriptiveText\">Is this spot a live read?</TD>  <TD class=\"formElementTextLeft\"> \n");
							if($live == 'true'){
							echo("<INPUT name=\"live$i\" type=\"checkbox\" value=\"true\" checked> Yes \n");
							}else{
							echo("<INPUT name=\"live$i\" type=\"checkbox\" value=\"true\"> Yes \n");
							}
					    echo("</TD></TR> \n \n");						
						//#####################################
						//UPDATE - TRADE? 						
						//#####################################	
						echo("<script language=\"JavaScript\" type=\"text/javascript\"> \n
						<!--
						function noRate$i(){  \n
							if(document.form.rate$i.value == \"NA\"){
							document.form.rate$i.value = \"\";						
							}else{
							document.form.rate$i.value=\"NA\";  \n
							}
						}  \n
						//-->  \n
						</script>  \n");
						
					    echo("<TR class=\"even\"><TD class=\"formDescriptiveText\">Is this spot a trade?</TD>  <TD class=\"formElementTextLeft\">  \n");
							if($trade == 'true'){
							echo("<INPUT name=\"trade$i\" type=\"checkbox\" value=\"true\" onClick=\"noRate$i()\" checked> Yes \n");
							}else{
							echo("<INPUT name=\"trade$i\" type=\"checkbox\" value=\"true\" onClick=\"noRate$i()\"> Yes \n");
							}
					    echo("</TD> </TR> \n");		
																	
							
		echo "</TABLE>";
		//END REPEATING SECTION
		++$i;

		}
				
		echo("</TD><TR>");
		echo("<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\"><INPUT name=\"mulitpleHighNumber\" type=\"hidden\" value=\"$i\"><INPUT name=\"action\" type=\"hidden\" value=\"updateOldGridItems\"><INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"formCheck()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"button\" class=\"inputButton\"  value=\"Reset\" onClick=\"resetForm()\"></TD></FORM></TR>");
		echo("</TABLE>");
		
		

?>